package com.coolwalker.common.domain;

import java.io.Serializable;

/**
 * 分页返回对象
 *
 * @author xuebing
 * @date 2019-08-05
 */
public class PageResult<T> extends Result<T> implements Serializable {

    private static final long serialVersionUID = 9112871060586105528L;

    /**
     * 当前页号
     */
    private Integer currentPageNum;

    /**
     * 每页记录数
     */
    private Integer pageSize;

    /**
     * 总记录数
     */
    private Long total;

    public static <T> PageResult<T> success(T data, Integer currentPageNum, Integer pageSize, Long total) {
        PageResult<T> result = new PageResult<>();
        result.setSuccess(Boolean.TRUE);
        result.setData(data);
        result.setCurrentPageNum(currentPageNum);
        result.setPageSize(pageSize);
        result.setTotal(total);
        return result;
    }

    public static <T> PageResult<T> error(int errorCode, String errorMessage, String innerMessage) {
        PageResult<T> result = new PageResult<>();
        result.setSuccess(Boolean.FALSE);
        result.setErrorCode(errorCode);
        result.setErrorMessage(errorMessage);
        result.setInnerMessage(innerMessage);
        return result;
    }

    public static <T> PageResult<T> error(int errorCode, String errorMessage) {
        return error(errorCode, errorMessage, null);
    }

    public static <T> PageResult<T> error(ErrorCode errorCode) {
        return error(errorCode.getCode(), errorCode.getMessage(), null);
    }

    public static <T> PageResult<T> error(ErrorCode errorCode, String innerMessage) {
        return error(errorCode.getCode(), errorCode.getMessage(), innerMessage);
    }

    public Integer getCurrentPageNum() {
        return currentPageNum;
    }

    public void setCurrentPageNum(Integer currentPageNum) {
        this.currentPageNum = currentPageNum;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public Long getTotal() {
        return total;
    }

    public void setTotal(Long total) {
        this.total = total;
    }
}
